#!/usr/bin/bash

DBFUNC_H=dbfunc.h
DBFUNC_OLD_H=dbfunc_old.h

TABLE=$1
TABLE_SQL=${TABLE}.sql
TABLE_H=$TABLE.h
TABLE_PC=${TABLE}_auto.pc

gendb $TABLE_SQL $TABLE_H $TABLE_PC
if [ $? != 0 ]
then
    echo "gendb fail"
    exit 1
fi
if [ ! -f $DBFUNC_H ]
then
    touch $DBFUNC_H
fi
mv -f $DBFUNC_H $DBFUNC_OLD_H
nawk -f mergedb.awk $DBFUNC_OLD_H $TABLE_H > $DBFUNC_H
rm -f $TABLE_H
